var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "TrainNumber",
			name : "行车编号"
		}, {
			colkey : "indate",
			name : "有效日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
			
		}, {
			colkey : "inCompanyName",
			name : "保险公司名字"
		},{
			colkey : "commercialinDate",
			name : "商业保险有效期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
				
		},{
			colkey : "strongpayinDate",
			name : "交强保险有限期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
				
		},{
			colkey : "buycarDate",
			name : "购车时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "embraceNo",
			name : "不开围板车车厢体积"
		},{
			colkey : "embrace1",
			name : "开一个车厢体积"
		},{
			colkey : "embrace2",
			name : "开二个车厢体积"
		},{
			colkey : "SeasonReviewDate",
			name : "季审日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "carRegister",
			name : "车辆登记表"
		},{
			colkey : "taiyuanDate",
			name : "泰源签合同日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}],
		jsonUrl : rootPath + '/transporTrecord/transportrecord_findbyPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#editFun").click("click", function() {
		editAccount();
	});
	$("#addFun").click("click", function() {
		addAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
	function editAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox.length > 1 ) {
			layer.msg("只能选中一个");
			return;
		}
		if(cbox == ""){
			layer.msg("需要选择一个");
			return;
		}
		pageii = layer.open({
			title : "编辑",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transporTrecord/transport_edit.shtml?id=' + cbox
		});
	}
	function addAccount() {
		pageii = layer.open({
			title : "添加运输申请",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transporTrecord/transport_add.shtml'
		});
	}
	
	function delAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox == "") {
			layer.msg("请选择删除项！！");
			return;
		}
		layer.confirm('是否删除？', function(index) {
			var url = rootPath + '/transporTrecord/transporTrecord_deleteEntity.shtml';
			var s = CommnUtil.ajax(url, {
				ids : cbox.join(",")
			}, "json");
			if (s == "success") {
				layer.msg('删除成功');
				grid.loadData();
			} else {
				layer.msg('删除失败');
			}
		});
	}
});